﻿/*!
 * 远光ECP平台3.4版本 
 * 
 * 可见窗口基类.：qzz.ui.Window
 * ecp.qzz.ui.window.js
 * @requires qzz.ui
 */

/**
 *可见控件命名空间
 *@name qzz.ui
 *@namespace qzz.ui
 */
define(["qzz.object"], function() {
	
 	var qzz = window.qzz;
	
	qzz.space("ui");   
	//后期加载样式
	require(["css!themes/default/qzz/ecp.qzz.css"],function(){
		qzz.ui.cssloaded = true;
	});	
	/**
	 @description 可见控件基类 
	<pre> 
	此类作为可见控件的基类来应用。
	</pre>
	@class qzz.ui.Window 可见控件基类
	@extends qzz.BaseObject
	@property
	@example
	@author qinzhenzhou@ygsoft.com
	@version 1.0
	@date 2014-03-01
	*/	
	qzz.ui.window = qzz.Class(qzz.object, 
	/**@lends qzz.ui.Window# */	
	{
		/**
		 * 初始化函数.
		 * @param {dom} control DOM元素
		 * @param {object} option 属性
		 * @ignore
		 */
	    init:function(control, option) {
	    	if(option == null) {
	    		if(control != null && (control.selector != null && control.length == 1 
	    				|| control.getAttribute != null && control.getAttribute("nodeType") == 1)) {
	    			//如果是dom元素
	    		} else {
	    			option = control;
	    			control = null;
	    		}
	    	}
	    	try {
		    	if(control != null) {
			    	this.control = $(control);
					this.control.attr("ecpclass", this.getEcpType());		    	
					this.name = this.control.attr("dataField");// || this.control.attr("name") || this.control.attr("id");
					// 获取页面控件自定义属性
								
			        var ctlInputer = $(control).attr("data-option");
			    	try{
			    		if(ctlInputer != null && typeof ctlInputer == "") {
			    		    ctlInputer = this.trim(ctlInputer);
			    		    if(ctlInputer.indexOf("{") == 0 || ctlInputer.indexOf("[") == 0) {
			    		    	ctlInputer = $.parseJSON(ctlInputer);
			    		    }			    		    
			    		}
			    		this.inputer = ctlInputer;
			    	}catch(e){
			    		this.logInfo("inputer to Json error!" + e.message + e.stack);
			    	}
			    	if(option && option.inputer){
			    		metaItem = option;
                                        var refTypeValues = metaItem.refTypeValues;
                                        var dataType = metaItem.dataType;
			    		ctlInputer && (metaItem.inputer = this.extend(metaItem.inputer, ctlInputer));
			    		option = this.extend(option, metaItem.inputer.option);
                                        if(refTypeValues != null && dataType === "sysenum") {
                                            option.data = null;
                                        }
			    	} else {
			    		ctlInputer && (option = this.extend(option, ctlInputer.option));
			    		metaItem = {inputer:{option:option}};
			    	}
			    	
			    	this.dataField = this.control.attr("dataField");
					this.control.data("_ecpUI", this);
		    	}
		    	this.base(option);
			    //this.logInfo("Window.init");
			    //键盘的键值
			    this.keyBoard = {
					ENTER : 13,    // 回车
					TAB : 9,       // Tab
					UP : 38,       // 向上
					DOWN : 40,     // 向下
					Left : 37,     // 向左 
					Right : 39,    // 向右
					LEFT : 37,     // 向左 
					RIGHT : 39,    // 向右
					BACKSPACE : 8, // 回退
				    ESC : 27,      // Escape
				    DEL : 46,      // 删除
				    PAGEUP : 33,   // 上一页
				    PAGEDOWN : 34, // 下一页
				    F1 : 112,      // F1
				    F2 : 113,      // F2
				    F3 : 114,      // F3
				    F4 : 115,      // F4
				    F5 : 116,      // F5
				    F6 : 117,      // F6
				    F7 : 118,      // F7
				    F8 : 119,      // F8
				    F9 : 120,      // F9
				    F10 : 121,     // F10
				    F11 : 122,     // F11
				    F12 : 123,     // F12
				    C : 67,
				    D : 68,
				    N : 78,		
				    F : 84,
				    O : 79,
				    P : 80,
				    LArrow : 188,
				    RArrow : 190,
				    V : 86,
				    X : 88,
				    Z : 90,
				    CTRL : 17,
				    A : 65,
				    HOME : 36,
				    END : 35,
				    ESC : 27,
				    SHIFT : 16,
				    PgUp : 33,
				    PgDn : 34
				};
			    /**
			     * dom元素相关宽度样式
			     */
				this.ELEM_WIDTH_STYLE = ["border-left-width","border-right-width","padding-left","padding-right","margin-left","margin-right"],
				
			    /**
			     * dom元素相关宽度样式
			     */ 
				this.ELEM_HEIGHT_STYLE = ["border-top-height","border-bottom-height","padding-top","padding-bottom","margin-top","margin-bottom"],

			    /**
			     * IE下dom元素相关宽度样式
			     */
				this.IE_ELEM_WIDTH_STYLE = ["borderLeftWidth","borderRightWidth","paddingLeft","paddingRight","marginLeft","marginRight"],
				
			    /**
			     * IE下dom元素相关宽度样式
			     */ 
				this.IE_ELEM_HEIGHT_STYLE = ["borderTopHeight","borderBottomHeight","paddingTop","paddingBottom","marginTop","marginBottom"],

				
			    //鼠标键值
			    this.mouseType = {mtLeft : "L",
			                      mtRight: "R"};
			    this._cssPrefix = "";
			    //样式前辍
			    if(this.isNotEmpty(this.getOption().cssPrefix)) {
		    		this._cssPrefix = this.getOption().cssPrefix;
		    	}
			    this._textSpan = document.getElementById("textSpan");
			    if(this._textSpan == null) {
			        this._textSpan = this.createElement("span");
			        this._textSpan.setAttribute("id","textSpan");
			        this.getBody()[0].appendChild(this._textSpan);
			    }
		    	this.setStyle(this._textSpan, "testSpan");	            
	            this._textSpan.style.display = "none";
			    //调用渲染函数
			    this._render();
			    //调用渲染后函数
			    this._afterRender();
			    //事件列表
			    this._eventList = {};		    
			    
			    this.body = null;
	    	} catch(e) {
	    		this.logError("init error:" + e.message + e.stack);
	    	}
	    	if(window._qzz_component_list == null) {
	    		window._qzz_component_list = {};
	    	}
	    	window._qzz_component_list[this.index] = this;
	    },
	    /**
	     * 对象创建函数.
	     */
	    _create:function() {
            this.className = "Window";
            //this.logInfo("Window.create");
            //刷新控制
            this._update = true;
            //父级控件对象
		    this.parent;
		    //子控件对象
		    this.childComponent = [];
		    this.tmpResize = "";
		    //是否可编辑
		    this._enabled = !(this.getBooleanValue(this.getOption().disabled, false));
		    //是否只读
		    this._readOnly = this.getBooleanValue(this.getOption().readOnly, false);
		    //是否只读
		    this._readOnly = !(this.getBooleanValue(this.getOption().editable, true));
		    //宽度初始化
		    if(this.getOption().width == null && this.control != null && this.control.length > 0) {
		    	this.getOption().width = this._getNumberValue(this.control[0].style.width, 10);
		    }
		    if(typeof this.getOption().width != "string" || !/[\d]+%$/.test(this.getOption().width)) {
		        this.getOption().width = this._getNumberValue(this.getOption().width, 10);
		    }
		    //高度初始化
		    if(typeof this.getOption().height != "string" || !/[\d]+%$/.test(this.getOption().height)) {
		        this.getOption().height = this._getNumberValue(this.getOption().height, 10);
		    }
		    //外边距初始化
		    this.getOption().margin = this._getNumberValue(this.getOption().margin, "");
		    this.getOption().marginLeft = this._getNumberValue(this.getOption().marginLeft, "");
		    this.getOption().marginRight = this._getNumberValue(this.getOption().marginRight, "");
		    this.getOption().marginTop = this._getNumberValue(this.getOption().marginTop, "");
		    this.getOption().marginBottom = this._getNumberValue(this.getOption().marginBottom, "");
		    //内边距初始化
		    this.getOption().padding = this._getNumberValue(this.getOption().padding, "");
		    this.getOption().paddingLeft = this._getNumberValue(this.getOption().paddingLeft, "");
		    this.getOption().paddingRight = this._getNumberValue(this.getOption().paddingRight, "");
		    this.getOption().paddingTop = this._getNumberValue(this.getOption().paddingTop, "");
		    this.getOption().paddingBottom = this._getNumberValue(this.getOption().paddingBottom, "");
		    //内边距初始化
		    this.getOption().border = this.getOption().border || "";
		    this.getOption().borderLeft = this.getOption().borderLeft || "";
		    this.getOption().borderRight = this.getOption().borderRight || "";
		    this.getOption().borderTop = this.getOption().borderTop || "";
		    this.getOption().borderBottom = this.getOption().borderBottom || "";
            //边距宽度
		    this.getOption().borderWidth = this._getNumberValue(this.getOption().borderWidth, "");
		    this.getOption().borderLeftWidth = this._getNumberValue(this.getOption().borderLeftWidth, "");
		    this.getOption().borderRightWidth = this._getNumberValue(this.getOption().borderRightWidth, "");
		    this.getOption().borderTopWidth = this._getNumberValue(this.getOption().borderTopWidth, "");
		    this.getOption().borderBottomWidth = this._getNumberValue(this.getOption().borderBottomWidth, "");
		    
		    this.getOption().fontSize = this._getNumberValue(this.getOption().fontSize, "");
		    this.getOption().defFontSize = this._getNumberValue(this.getOption().fontSize, 14);
		    this.getOption().designer = this.getBooleanValue(this.getOption().designer, false);
		    
		    //初始化DOM框架
		    var controls = this.getControl();
		    if(this.isNotEmpty(controls) && controls.length > 0) {
		    	this.thisWindow = controls[0];
			    var parent = controls.parent();
		    	if(this.isNotEmpty(parent[0]._object)) {
		    		parent = parent[0]._object;
		    	}
		    	this.setParent(parent, true);
		    	this.thisWindow._object = this;
		    	parent = null;
	    	}
		    controls = null;
		    this.focus = false;
		    this.hasSelect = false;
		    //兼容ie10鼠标没有弹起就激活mouseup的问题
		    this._hasclick = true;
		    this._atop = null;
		    this._aleft = null;
		    //每个字占用的宽度系数
		    this._sizew = 0.30;
		    //每个字占用的行高系数
		    this._sizeh = 1.30;
		    this.getOption().top = this._getNumberValue(this.getOption().top, 0);
		    this.getOption().left = this._getNumberValue(this.getOption().left, 0);
		    //用于缓存dom元素，IE下不缓存，内容会丢失.
		    this.docFragment = document.createDocumentFragment();
	    },
	    /**
	     * 渲染函数.
	     */
	    _render:function() {
	    	var element = this.control;

	    	//this.logInfo("Window.render");
	    	//如果不存在，则创建
	    	if(element == null || element.length == 0) {    	
	    	    this.thisWindow = this.createElement("div");
	    	    this.control = [this.thisWindow];
	    	    //传入父节点时
	    	    if(this.getOption().parent != null) {
		    		var parent = this.getOption().parent;
		    		if(!parent.isComponent && parent[0] != null 
		    				&& this.isNotEmpty(parent[0]._object)) {
			    		parent = parent[0]._object;
			    	}
			    	this.setParent(parent);
			    	this.thisWindow._object = this;
			    	this.getOption().parent = null;
			    	parent = null;
		    	}
	    	}
	    	
	    	if((typeof this.doContainerHide == "function" || typeof this.doContainerShow == "function") 
	    			&& !this.isShow()) {
	    		this._showState = false;
	    		this.logInfo("show handel has set");
	    	}
	    	//设置样式
	    	this.setStyle(this.thisWindow, "winStyle");
	    	//边距处理
	    	this._setNumberValue(this.thisWindow, "margin", this.getOption().margin);
	    	this._setNumberValue(this.thisWindow, "marginLeft", this.getOption().marginLeft);
	    	this._setNumberValue(this.thisWindow, "marginRight", this.getOption().marginRight);
	    	this._setNumberValue(this.thisWindow, "marginTop", this.getOption().marginTop);
	    	this._setNumberValue(this.thisWindow, "marginBottom", this.getOption().marginBottom);
	    	this._setNumberValue(this.thisWindow, "padding", this.getOption().padding);
	    	this._setNumberValue(this.thisWindow, "paddingLeft", this.getOption().paddingLeft);
	    	this._setNumberValue(this.thisWindow, "paddingRight", this.getOption().paddingRight);
	    	this._setNumberValue(this.thisWindow, "paddingTop", this.getOption().paddingTop);
	    	this._setNumberValue(this.thisWindow, "paddingBottom", this.getOption().paddingBottom);
	    	this._setNumberValue(this.thisWindow, "borderWidth", this.getOption().borderWidth);
	    	this._setNumberValue(this.thisWindow, "borderLeftWidth", this.getOption().borderLeftWidth);
	    	this._setNumberValue(this.thisWindow, "borderRightWidth", this.getOption().borderRightWidth);
	    	this._setNumberValue(this.thisWindow, "borderTopWidth", this.getOption().borderTopWidth);
	    	this._setNumberValue(this.thisWindow, "borderBottomWidth", this.getOption().borderBottomWidth);
	    	//直接设置border样式.
	    	if(this.getOption().border !== "") {
	    	    this.thisWindow.style.border = this.getOption().border;
	    	}
	    	if(this.getOption().borderLeft !== "") {
	    		this.thisWindow.style.borderLeft = this.getOption().borderLeft;
	    	}
	    	if(this.getOption().borderRight !== "") {
	    		this.thisWindow.style.borderRight = this.getOption().borderRight;
	    	}
	    	if(this.getOption().borderTop !== "") {
	    		this.thisWindow.style.borderTop = this.getOption().borderTop;
	    	}
	    	if(this.getOption().borderBottom !== "") {
	    		this.thisWindow.style.borderBottom = this.getOption().borderBottom;
	    	}

	    	this._setNumberValue(this.thisWindow, "top", this.getOption().top);
	    	this._setNumberValue(this.thisWindow, "left", this.getOption().left);	    	
	    	if(this.getOption().borderStyle != null) {
	    	    this.thisWindow.style.borderStyle = this.getOption().borderStyle;
	    	}
	    	if(this.getOption().radius != null) {
	    		this.thisWindow.style.borderRadius = this.getOption().radius + "px";
	    	}

	    	if(this.getOption().borderColor != null) {
	    		this.thisWindow.style.borderColor = this.getOption().borderColor;
	    	}	    		    	
	    	if(/[\d]+%$/.test(this.getOption().width)) {
	    		this.thisWindow.style.width = this.getOption().width;
	    	} else {
	    	    this._setNumberValue(this.thisWindow, "width", this.getOption().width);
	    	}
	    	if(/[\d]+%$/.test(this.getOption().height)) {
	    		this.thisWindow.style.height = this.getOption().height;
	    	} else {
	    	    this._setNumberValue(this.thisWindow, "height", this.getOption().height);
	    	}
	    	
	    	if(this.getOption().fontSize != null && this.getOption().fontSize !== "") {
	    		this._setNumberValue(this.thisWindow, "fontSize", this.getOption().fontSize);
	    	} else {
	    		this.thisWindow.style.fontSize = "12px";
	    		this.getOption().fontSize = 12;
	    	}
	    	if(this.getOption().textAlign != null && this.getOption().textAlign !== "") {
	    		this.thisWindow.style.textAlign = this.getOption().textAlign;
	    	}
	    	//处理大小变量
	    	if(this._hasResize()) {
	    	    this._doResize();
	    	}
	    },
	    isMouseOver:function() {
	    	return this._mouseover;
	    },
	    /**
	     * 渲染后执行.
	     */
	    _afterRender:function(){
	    	//this.logInfo("Window.afterRender");
	    	var _this = this;
	    	//兼容ie10鼠标没有弹起就激活mouseup的问题
	    	this.thisWindow.onmousedown = function() {
	        	_this._hasclick = false;
	        };
	    	this.thisWindow.onmouseup = function() {
	    		//兼容ie10鼠标没有弹起就激活mouseup的问题
	    		_this._hasclick = true;
	        	_this.hasSelect = true;
	        };
	        this.thisWindow.onmouseover = function() {
	        	_this._mouseover = true;
	        }
	        this.thisWindow.onmouseout = function() {
	        	_this._mouseover = false;
	        }
	        if(this.getOption().designer == true &&
	        		this.getOption().caption != null && this.getOption().caption !== "") {
	        	if(this._capSpan == null) {
	        		this._capSpan = this.createElement("DIV");
	        		this.setStyle(this._capSpan, "winCaptionStyle");
	        		this.thisWindow.appendChild(this._capSpan);
	        	}
	        	this._setHtml(this._capSpan, this.getOption().caption);
	        }
	        if(this.getOption().title != null && this.getOption().title !== "") {
	        	this.thisWindow.title = this.getOption().title;
	        }
	        this._isShow = this.thisWindow.offsetWidth > 0;
	        //系统事件
	        this._sysEvent();
	    },
	    /**
	     * 返回控件的id
	     */
	    getID : function() {
	    	if(this.id == null) {
	    		this.id = this.thisWindow.id;
	    	}
	    	return this.id;
	    },
	    getNumberValue:function(value, def) {
	    	return this._getNumberValue(value, def);
	    },
	    /**
	     * 获取dom的数值.
	     * value 值,
	     * def 默认
	     * 返回结果
	     */
	    _getNumberValue:function(value, def) {
	    	var reVal = value
	    	var reDef = def;
	    	if(this.isNotEmpty(reVal)) {
	    		//如果是字符串，则转换成整形
	    		if(typeof reVal == "string") {
	    			reVal = reVal.replace(/px/, "");
	    			if(this.isEmpty(reVal)) {
	    				reVal = reDef;
	    			} else {
	    				reVal = parseInt(reVal, 10);
	    			}
	    		}
	    	} else {
	    		reVal = reDef;
	    	}
	    	return reVal;
	    },
	    /**
	     * 大小是否发生变化.
	     */
	    _hasResize:function() {
	    	return !(this.thisWindow.style.top == this.getOption().top + "px" 
	    	         && this.thisWindow.style.left == this.getOption().left + "px"
	    	             && this.thisWindow.style.width == this.getOption().width + "px"
	    	                 && this.thisWindow.style.height == this.getOption().height + "px");
	    },
	    /**
	     * 执行变化调整事件.
	     * @return 返回状态
	     */
	    _doResize:function() {
	    	if(!this._update) return false;
	    	this.logBegin("_doResize:" + this.getOption().width);
	    	var msg = "";
	    	//设置位置
	    	var mgt = this.getTop();
	    	var oldV = this.thisWindow.style.top;
	    	if(this._setNumberValue(this.thisWindow, "top", mgt)) {
	    		msg += this.getName() + " top:" + oldV + " to " + mgt + "\n";
	    	}
	    	var mgl = this.getLeft();
	    	oldV = this.thisWindow.style.left;
	    	if(this._setNumberValue(this.thisWindow, "left", mgl)) {
	    		msg += this.getName() + " left:" + oldV + " to " + mgl + "\n";
	    	}
	    	//处理大小
	    	var bw = this.getWidth();
	    	if(bw <= 0) {
	    		bw = 1;
	        }
	    	if(/\d+%$/.test(bw) ===  true) {
	    		this.thisWindow.style.width = bw;
	    	} else if(!/\d+%$/.test(this.thisWindow.style.width)) {
		        oldV = this._getNumberValue(this.thisWindow.style.width, 1);
		        //var oldf = this.thisWindow.offsetWidth;	        
		        if((bw < oldV || bw > oldV + 2) || !this.getBrowser("msie")) {
			    	if(this._setNumberValue(this.thisWindow, "width", bw)) {
			    		msg += this.getName() + " width:" + oldV + " to " + bw + "\n";
			    	}
		        }
	    	}
	    	var bh = this.getHeight();
	    	if(bh <= 0) {
	    		 bh = 1;
	    	}
	    	if(/\d+%$/.test(bh) ===  true) {
	    		this.thisWindow.style.height = bh;
	    	} else if(!/\d+%$/.test(this.thisWindow.style.height)) {
		    	oldV = this.thisWindow.style.height;
		    	if(this._setNumberValue(this.thisWindow, "height", bh)) {
		    		msg += this.getName() + " height:" + oldV + " to " + bh + "\n";
		    	}
	    	}
	    	this.logEnd("_doResize " + msg);
	    },
	    /**
	     * 获取top位置.
	     */
	    _getRectTop:function(el) {
	    	return this._getPaddingTop(el); //this.getOption().top + 	    	    
	                           //+ this._getBorderTop(el);//border 自动包含在内了
	    },
	     /**
	      * 获取left位置.
	      */
	    _getRectLeft:function(el) {
	    	return this._getPaddingLeft(el); //this.getOption().left + 
						        //+ this._getBorderLeft(el);//border 自动包含在内了
	    	
	    },
	    /**
	     * 获取内宽.
	     * @return 返回宽度
	     */
	    _getRectWidth:function(el) {
	    	var width = this.getWidth();
		    if(this.isNotEmpty(el)) {
		    	if(el.tagName == null && el.length > 0) {
				    el = el[0];
				}
                if(el.tagName == "BODY") {
				    width = this._getBodyWidth();
					if(this.isEmpty(el.style.marginLeft)) {
						el.style.marginLeft = "0px";
					}
					if(this.isEmpty(el.style.marginRight)) {
						el.style.marginRight = "0px";
					}
				} else {		
					if(el._width == null) {
				        width = el.offsetWidth;
				        //this.logInfo("++++++++++++++++++++++++++++++++2:" + width);
					} else {
						width = el._width;
					}
				}
			} else if(/\d+%$/.test(width)) {
		    	width = this.thisWindow.offsetWidth;
		    }
		    //边距减去边线与内边框
	    	width -= this._getPaddingLeft(el)
			       + this._getPaddingRight(el)
				   + this._getBorderLeft(el) 
				   + this._getBorderRight(el);
	    
			return width;
	    },
	    /**
	     * 获取内高.
	     * @return 返回高度
	     */
	    _getRectHeight:function(el) {
	    	 var height = this.getHeight();
			 if(this.isNotEmpty(el)) {
				 if(el.tagName == null && el.length > 0) {
					el = el[0];
				}
				if(el.tagName == "BODY") {
				    height = this._getBodyHeight();
					if(this.isEmpty(el.style.marginTop)) {
						el.style.marginTop = "0px";
					}
					if(this.isEmpty(el.style.marginBottom)) {
						el.style.marginBottom = "0px";
					}
				} else {
					if(el._height == null) {
				        height = el.offsetHeight;
					} else {
						height = el._height;
					}
				}    
			} else  if(/\d+%$/.test(height)) {
				height = this.thisWindow.offsetHeight;
			}
			//边距减去边线与内边框
		    height -= this._getPaddingTop(el) 
		            + this._getPaddingBottom(el)
			        + this._getBorderTop(el) 
	 	            + this._getBorderBottom(el);		
			return height;
	    },
	    /**
	     * 获取边左线.
	     * @param el 元素
	     * @return 返回宽度
	     */
	    _getBorderLeft:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.borderLeftWidth;
	    	} else {
	    		v = $(el).css("borderLeftWidth");
	    	}
	    	if(v === "medium") {
	    		v = "";
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取右边线
	     * @param el 元素
	     * @return 返回宽度
	     */
	    _getBorderRight:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.borderRightWidth;
	    	} else {
	    		v = $(el).css("borderRightWidth");
	    	}
	    	if(v === "medium") {
	    		v = "";
	    	}
	    	return this._getNumberValue(v, 0);
	    },
		/**
		 * 获取上边线
		 * @param el 元素
		 * @return 返回宽度
		 */
	    _getBorderTop:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.borderTopWidth;
	    	} else {
	    		v = $(el).css("borderTopWidth");
	    	}
	    	if(v === "medium") {
	    		v = "";
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取下边线
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getBorderBottom:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.borderBottomWidth;
	    	} else {
	    		v = $(el).css("borderBottomWidth");
	    	}
	    	if(v === "medium") {
	    		v = "";
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取左外边距
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getMarginLeft:function(el) {
	    	var el = el || this.thisWindow;	   
	    	if(el.tagName == null && el.length > 0) {
				    el = el[0];
				}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.marginLeft;
	    	} else {
	    		v = $(el).css("marginLeft");
	    	}
	    	if(v === "auto") {
	    		v = "";
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取右外边距
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getMarginRight:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.marginRight;
	    	} else {
	    		v = $(el).css("marginRight");
	    	}
	    	if(v === "auto") {
	    		v = "";
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取上外边距
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getMarginTop:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.marginTop;
	    	} else {
	    		v = $(el).css("marginTop");
	    	}
	    	if(v === "auto") {
	    		v = "";
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取下外边距
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getMarginBottom:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;	    	
	    	if(el.tagName == "BODY") {
	    		v = el.style.marginBottom;
	    	} else {
	    		v = $(el).css("marginBottom");
	    	}
	    	if(v === "auto") {
	    		v = "";
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取左内边距.
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getPaddingLeft:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.paddingLeft;
	    	} else {
	    		v = $(el).css("paddingLeft");
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取右内边距.
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getPaddingRight:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.paddingRight;
	    	} else {
	    		v = $(el).css("paddingRight");
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取上内边距.
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getPaddingTop:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.paddingTop;
	    	} else {
	    		v = $(el).css("paddingTop");
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取下内边距.
	     * @param el 元素
		 * @return 返回宽度
	     */
	    _getPaddingBottom:function(el) {
	    	var el = el || this.thisWindow;
	    	if(el.tagName == null && el.length > 0) {
			    el = el[0];
			}
	    	var v = 0;
	    	if(el.tagName == "BODY") {
	    		v = el.style.paddingBottom;
	    	} else {
	    		v = $(el).css("paddingBottom");
	    	}
	    	return this._getNumberValue(v, 0);
	    },
	    /**
	     * 获取body元素.
	     * @return body元素
	     */
	    getBody:function() {
	    	if(this.body == null) {
	    		this.body = $("body");
	    	}
	    	return this.body;
	    },
	    /**
	     * 模态窗口的时候，筛选窗口输入不了.
	     */
	    getModelBody:function() {
	    	if(this.modelBody == null) {
	    		this.modelBody = $(this.getControl()).parents('[tabindex=-1]');
	    		if(this.modelBody == null || this.modelBody.length == 0) {
	    			this.modelBody = $(this.getControl()).parents('.modal-dialog');
	    			if(this.modelBody.length > 0) {
	    				this.modelBody = this.modelBody.parent();
	    			}
	    		}
	    		if(this.modelBody == null || this.modelBody.length == 0) {
	    			this.modelBody = this.getBody();
	    			this.inModelBody = false;
	    		} else {
	    			this.inModelBody = true;
	    		}
	    	}
	    	return this.modelBody;
	    },
	    /**
	     * 获取body元素宽度.
	     * @return body宽度
	     */
	    _getBodyWidth:function() {
	    	if(this.getBrowser("safari")) {
	    		return document.documentElement.clientWidth;
	    	} else {
	    		return this.getBody().width();
	    	}
	    },
	    /**
	     * 获取body元素高度.
	     * @return body高度
	     */
	    _getBodyHeight:function() {	    	
    		var h1 = this.getBody().height();
    		var h2 = document.documentElement.clientHeight;
    		if(h1 < h2) {
    			h1 = h2;
    		}
    		return h1;
	    },
	    /**
	     * 获取事件源.
	     * @param ent 事件对象
	     * @return 返回
	     */
	    getEventTarget:function(ent) {
	    	return ent.target || ent.srcElement;
	    },
	    /**
	     * 鼠标按下.
	     * @param ev 事件对象
	     */
	    _docMouseDown:function(ev) {
            if(this._enabled && (this.hasSelect || this.focus)) {
                this.doMouseDown(ev);
                if(this._createEditObject !== true) {
                    this.hasSelect = false;
                }
                this._createEditObject = false;
            }
	    },
	    /**
	     * 鼠标弹起.
	     * @param ev 事件对象
	     */
	    _docMouseUp:function(ev) {
            if(this._enabled && this._hasclick == true && (this.hasSelect || this.focus)) {
                if(this.hasSelect) {
                	//牌选择状态
                	if(!this.focus) {
                		//处理焦点事件
                		this.setFocus();
                	}
                } else {
                	//没有选择状态
                	if(this.focus) {
	                    //失去焦点事件
	                	this.setBlur();
                	}
                }
                this.doMouseUp(ev);
                //this.logInfo("doc mouse up!");
                this.hasSelect = false;
            }
            //兼容ie10鼠标没有弹起就激活mouseup的问题
            this._hasclick = true;
	    },
	    /**
	     * 鼠标移动.
	     * @param ev 事件对象
	     */
	    _docMouseMove:function(ev) {
	    	if(this._enabled && (this.hasSelect || this.focus)) {
	    		this.doMouseMove(ev);
	    		this.hasSelect = false;
	    	}	    	
	    },
	    /**
	     * 样式加载完成.
	     */
	    _docCssLoaded:function() {
	    	if(typeof this.doCssLoaded == "function") {
	    		this.doCssLoaded();
	    	}
	    },
	    _docShow:function() {
	    	if(typeof this.doContainerHide == "function") {		    				
				this.doContainerHide();
			}
	    	this.doShow();
	    },
	    _docHide:function() {
	    	if(typeof this.doContainerShow == "function") {
			    this.doContainerShow();
			}
	    	this.doHide();
	    },
	    /**
	     * 键盘弹起.
	     * @param ev 事件对象
	     */
	    _docKeyUp:function(ev) {
	    	if(this._enabled && this.focus) {
	    		var key = ev.keyCode || ev.charCode || ev.which;
                var re = this.doKeyUp(ev, key);                
                this.logInfo("doc key "+key+" up!"); 
                if(re == null) {
                	re = true;
                }
                if(!re) {
                	if(ev.preventDefault) {     
		    			// Firefox       
		    		    ev.preventDefault();       
		    		    ev.stopPropagation();     
		    		} else {       
		    			// IE       
		    		    ev.cancelBubble=true;       
		    		    ev.returnValue = false;
		    		}
                }
                key = null;
                ev = null;
                return re;
            }
	    },
	    /**
	     * 键盘按下.
	     * @param ev 事件对象
	     */
	    _docKeyDown:function(ev) {
	    	if(this._enabled && this.focus) {	    		
	    		var key = ev.keyCode || ev.charCode || ev.which;
                var re = this.doKeyDown(ev, key);  
                if(re == null) {
                	re = true;
                }
                //this.logInfo("doc key "+key+" down!");               
                if(!re) {
                	if(ev.preventDefault) {     
		    			// Firefox       
		    		    ev.preventDefault();       
		    		    ev.stopPropagation();     
		    		} else {       
		    			// IE       
		    		    ev.cancelBubble=true;       
		    		    ev.returnValue = false;
		    		}
                }
                key = null;
                ev = null;
                return re;
            }
	    },
	    /**
	     * 鼠标滚动.
	     * @param ev 事件对象
	     */
	    _docMouseWheel:function(ev) {
	    	if(this._enabled && this.focus) {
	    		if (ev.wheelDelta) {
		            scint = ev.wheelDelta;
		        } else {
		            scint = ev.detail * (-1);
		        }
        	    var re = this.doMouseWheel(ev, scint);
        	    if(re == null) {
        	    	re = true;
        	    }
        	    if(re === false || re === "false") {
                	if(ev.preventDefault) {     
		    			// Firefox       
		    		    ev.preventDefault();       
		    		    ev.stopPropagation();     
		    		} else {       
		    			// IE       
		    		    ev.cancelBubble=true;       
		    		    ev.returnValue = false;
		    		}
                }
                key = null;
                ev = null;
                return re;
        	}	    	
	    },
	    _docResize:function(ev) {
    		var re = this.doResize(ev)
    		if(re == null) {
    	    	re = true;
    	    }
    	    if(re === false || re === "false") {
            	if(ev.preventDefault) {     
	    			// Firefox       
	    		    ev.preventDefault();       
	    		    ev.stopPropagation();     
	    		} else {       
	    			// IE       
	    		    ev.cancelBubble=true;       
	    		    ev.returnValue = false;
	    		}
            }
            key = null;
            ev = null;
            return re;
	    },
	    /**
	     * 系统事件.
	     */
        _sysEvent:function(){
        	var _this = this;
        	/**
        	 * 事件列表
        	 */
        	this._eventList = {
                mouseup:function(ev) {
                	var ev = ev || window.event;
        		    _this._docMouseUp(ev);
        	    },
        	    mousedown:function(ev) {
        	    	var ev = ev || window.event;
        	    	_this._docMouseDown(ev);
        	    },
        	    mousemove:function(ev) {
        	    	var ev = ev || window.event;
        	    	_this._docMouseMove(ev);
        	    },
        	    keyup:function(ev) {
        	    	var ev = ev || window.event;
        	    	return _this._docKeyUp(ev);
        	    },
        	    keydown:function(ev) {
        	    	var ev = ev || window.event;
        	    	return _this._docKeyDown(ev);
        	    },
        	    mousewheel:function(ev) {
        	    	var ev = ev || window.event;
        	    	var re = _this._docMouseWheel(ev);
        	    	if(re === false || re === "false") {
          	    		evt = ev || window.event;     
        	    		if(evt.preventDefault) {     
        	    			// Firefox       
        	    		    evt.preventDefault();       
        	    		    evt.stopPropagation();     
        	    		} else {       
        	    			// IE       
        	    		    evt.cancelBubble=true;       
        	    		    evt.returnValue = false;
        	    		}
        	    		return false
        	    	}
        	    	return true;
        	    },
        	    resize:function(ev) {
        	    	var ev = ev || window.event;
        	    	return _this._docResize(ev);
        	    }
        	};
	    	if (window.addEventListener) {
                // 其它浏览器的事件代码: Mozilla, Netscape, Firefox
                // 添加的事件的顺序即执行顺序
                // 注意用 addEventListener 添加带on的事件，不用加on
                document.addEventListener("mousedown", this._eventList.mousedown, false);
                document.addEventListener("mouseup", this._eventList.mouseup, false);
                document.addEventListener("mousemove", this._eventList.mousemove, false);
                document.addEventListener("keydown", this._eventList.keydown, false);
                document.addEventListener("keyup", this._eventList.keyup, false);
                document.addEventListener('DOMMouseScroll',this._eventList.mousewheel,false);
                //chrome
                document.addEventListener('mousewheel',this._eventList.mousewheel,false); 
                window.addEventListener('resize',this._eventList.resize,false);
            } else {
                // IE 的事件代码 在原先事件上添加 add 方法
                document.attachEvent("onmousedown", this._eventList.mousedown); 
                document.attachEvent("onmouseup", this._eventList.mouseup);
                document.attachEvent("onmousemove", this._eventList.mousemove);
                document.attachEvent("onkeydown", this._eventList.keydown);
                document.attachEvent("onkeyup", this._eventList.keyup);
                document.attachEvent("onmousewheel", this._eventList.mousewheel);
                window.attachEvent("onresize", this._eventList.resize);
            }
	    	//处理显示隐藏事件
            if(window._qzz_component_show_handle == null) {
            	window._qzz_component_show_handle = setInterval(function() {
            		var isEmpty = true;
            		for(var key in window._qzz_component_list) {
            			var ccn = window._qzz_component_list[key];
            			if(ccn != null && ccn.isShow != null) {
            				if(ccn._isShow !== true && ccn.isShow() === true) {
            					ccn._isShow = true;
            					ccn._docShow();
            				} else if(ccn._isShow === true && ccn.isShow() === false) {
            					ccn._isShow = false;
            					ccn._docHide();
            				}
            			} else {
            				delete window._qzz_component_list[key];
            			}
            			isEmpty = false;
            		}
            		//如果没有可见列表，则清除掉.
            		if(isEmpty) {
            			clearInterval(window._qzz_component_show_handle);
            			window._qzz_component_show_handle = null;
            		}
		    	 },250);
		     }
             //监听样式文件加载情况.
             if(qzz.ui.cssloaded_listen == null && qzz.ui.cssloaded !== true) {
            	 qzz.ui.cssloaded_listen = setInterval(function() {
            		 if(qzz.ui.cssloaded === true) {
            			 for(var key in window._qzz_component_list) {
	            			 var ccn = window._qzz_component_list[key];
	             			 if(ccn != null && ccn.isShow != null) {
	             		 		ccn._docCssLoaded();
	             		 	 }
             			 }
            			 clearInterval(qzz.ui.cssloaded_listen);
            			 qzz.ui.cssloaded_listen = null;
            		 }
            	 }, 100);
             }
	    },
	    
	    clearEvent:function() {
	    	if (window.removeEventListener) {
                // 其它浏览器的事件代码: Mozilla, Netscape, Firefox
                // 添加的事件的顺序即执行顺序
                // 注意用 addEventListener 添加带on的事件，不用加on
                document.removeEventListener("mousedown", this._eventList.mousedown, false);
                document.removeEventListener("mouseup", this._eventList.mouseup, false);
                document.removeEventListener("mousemove", this._eventList.mousemove, false);
                document.removeEventListener("keydown", this._eventList.keydown, false);
                document.removeEventListener("keyup", this._eventList.keyup, false);
                document.removeEventListener('DOMMouseScroll',this._eventList.mousewheel,false); 
                document.removeEventListener('mousewheel',this._eventList.mousewheel,false); 
            } else {
                // IE 的事件代码 在原先事件上添加 add 方法             
                document.detachEvent("onmousedown", this._eventList.mousedown); 
                document.detachEvent("onmouseup", this._eventList.mouseup);
                document.detachEvent("onmousemove", this._eventList.mousemove); 
                document.detachEvent("onkeydown", this._eventList.keydown);
                document.detachEvent("onkeyup", this._eventList.keyup);
                document.detachEvent("onmousewheel", this._eventList.mousewheel);
            }
	    	if(this.showHandle != null) {
	    	    clearInterval(this.showHandle);
	    	    this.showHandle = null;
	    	}
	    },
	    /**
	     * 创建元素.
	     * @param tabName 元素名称
	     */
	    createElement:function(tabName) {
	    	return document.createElement(tabName);
	    },
	    /**
	     * 样式设置.
	     * @param tab 元素
	     * @param className 样式名
	     * @param doCss 设计样式
	     */
	    setStyle:function(tab, className, doCss, noPrefix){
	    	doCss = doCss || true;
	    	if(tab._option == null) {
    		    tab._option = {};	
    		}
	    	if(this.isArray(className)) {
	    		//在元素上设置格式数组对象
	    		if(noPrefix !== false) {
	    			for(var i = 0, len = className.length; i < len; i++) {
	    				className[i] = this._cssPrefix + className[i];
	    			}
	    		}	    		
	    		tab._option.cssAry = className;
	    		var cn = className.join(" ");
	    		if(tab.className != cn && doCss) {
	    			tab.className = cn;
	    		}
	    	} else {
	    		//直接设置样式
	    		if(noPrefix !== false) {
	    			className = this._cssPrefix + className;
	    		}
		    	if (tab.className != className) {
		    		if(doCss) {
		                tab.className = className;
		            }
		            tab._option.cssAry = [className];
		        }
	    	}
	    },
	    /**
	     * 添加样式.
	     * @param tab 元素
	     * @param className 样式名
	     * @param doCss 处理样式
	     */
	    addStyle:function(tab, className, doCss, before) {
	    	doCss = doCss || true;
	    	if(tab._option == null) {
	    	    tab._option = {};	
	    	}	    	
	    	if(tab._option.cssAry != null) {
	    		//检查重复
	    		var i = 0, len = tab._option.cssAry.length
	    		for(; i < len; i++) {
	    			if(tab._option.cssAry[i] == this._cssPrefix + className) {
	    				break;
	    			}
	    		}
	    		//添加样式
	    		if(i >= len) {
	    			if(before === true) {
	    				tab._option.cssAry.splice(0,0,this._cssPrefix + className);
	    			} else {
	    			    tab._option.cssAry.push(this._cssPrefix + className);
	    			}
	    		}
	    	} else {
	    		tab._option.cssAry = [this._cssPrefix + className];
	    	}
	    	if(doCss) {
	    		//设计样式到dom
	    		var ncs = tab._option.cssAry.join(" ");
	    		if(ncs !== tab.className) {
	    	        tab.className = ncs;
	    		}
	    	}
	    },
	    /**
	     * 清除样式.
	     * @param tab 元素
	     * @param doCss 执行样式.
	     */
	    clearStyle:function(tab, doCss) {
	    	if(tab._option == null) {
	    	    tab._option = {};	
	    	}
	    	if(tab._option.cssAry != null) {
	    		tab._option.cssAry = [];
	    	}
	    	doCss = doCss || true;
	    	if(doCss && tab.className !== "") {
	    	    tab.className = "";
	    	}
	    },
	    /**
	     * 删除样式.
	     * @param tab 元素
	     * @param className 样式名
	     * @param doCss 处理样式
	     */
	    delStyle:function(tab, className, doCss) {
	    	if(tab._option == null) {
	    	    tab._option = {};	
	    	} 
	    	if(tab._option.cssAry != null) {
	    		//查找需要删除的样式名
	    		var i = 0, len = tab._option.cssAry.length;
	    		for(; i < len; i++) {
	    			if(tab._option.cssAry[i] == className) {
	    				break;
	    			}
	    		}
	    		if(i < len) {
	    			tab._option.cssAry.splice(i, 1);
	    		}
	    	}
	    	doCss = doCss || true;
	    	if(doCss) {
	    		var ncs = tab._option.cssAry.join(" ");
	    		if(ncs !== tab.className) {
	    	        tab.className = ncs;
	    		}
	    	}
	    },
	    /**
	     * 设置tdtext值.
	     */
	    _setTdText : function(col, text, isHtml) {
	    	if(isHtml === true){
	    		$(col).html(text);
	    		return;
	    	}
	    	var i;
	    	var len = col.childNodes.length;
			for(i = 0; i < len; i++) {
				var cn = col.childNodes[i];
				if(cn.nodeName == "#text") {
					cn.nodeValue = text;
					break;
				}
			}
			if(i >= len) {
				for(i = 0; i < len; i++) {
					var cn = col.childNodes[i];
					if(cn.nodeName.toUpperCase() == "FONT") {
						cn.childNodes[0].nodeValue = text;
						break;
					}
				}
			}
	    },
	    /**
	     * 设置元素宽度.
	     */
	    _setNumberValue:function(el, option, value) {
	    	var tyf = typeof value;
	    	//只处理数值型，与字符串型的，其余的不处理
	    	if(tyf === "number" && !isNaN(value)
	    		|| tyf == "string" && value !=="" && !isNaN(value) && value.indexOf("px") < 0) {
	    		if(value <= 0 && (option === "width" || option === "height")) {
	    			value = 1;
	    		}
	    		value = value + "px";
	    		if(el.style[option] !== value) {
		    		el.style[option] = value;
		    		return true;
		    	}
	    	}	    	
	    	return false;
	    },
	    /**
	     * 颜色转换
	     * @param rgb 颜色
	     * @return 返回颜色
	     */
	    rgbToColor:function(rgb){
	    	if (rgb.indexOf("#") >= 0) {
		        return rgb;
		    }		        
		    // 如果是一个hex值则直接返回
		    var pattern = new RegExp("2[0-4]\\d|25[0-5]|[01]?\\d\\d?", "ig");
		    // 这个正则是取
		    // 0 ~
		    // 255的数字
		    var va = rgb.match(pattern);
		    if (va.length != 3) {
		    	va = null;
		    	pattern = null;
		        return "NaN";
		    }		        
		    // 取出的数组长度一定得为3
		    var result = "#";
		    for (var i = 0; i < 3; i++) {
		        var num = parseInt(va[i]);
		        result += num < 16 ? "0" + num.toString(16) : num.toString(16);
		        // 如果小于F在前面补0
		        num = null;
		    }
		    va = null;
		    pattern = null;
		    return result;
	    },
	    /**
	     * 获取滚动条位置.
	     * @return 位置
	     */
	    getScrollXY:function() {
	    	var scrollXY = {}; 
	    	if (typeof window.pageYOffset != 'undefined') {
	    		scrollXY["top"] = window.pageYOffset; 
	    		scrollXY["left"] = window.pageXOffset;
	    	} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
	    		scrollXY["top"] = document.documentElement.scrollTop;
	    		scrollXY["left"] = document.documentElement.scrollLeft; 
	    	} else if (typeof document.body != 'undefined') {
	    		scrollXY["top"] = document.body.scrollTop;
	    		scrollXY["left"] = document.body.scrollLeft;
	    	}
	    	//如果在
	    	if(this.inModelBody === true) {
	    		scrollXY["top"] = 0; 
	    		scrollXY["left"] = 0;
	    	}
	    	return scrollXY;
	    },
	    /**
	     * 获取当前窗口的绝对位置.
	     * @return 位置
	     */
	    getAXY:function() {
	    	var oRect = this.thisWindow.getBoundingClientRect();
	    	var sxy = this.getScrollXY();
    		this._aleft = oRect.left + sxy.left;     
    		this._atop = oRect.top + sxy.top;
	    },
	    /**
	     * 获取绝对top值.
	     * @return 返回top
	     */
	    getATop:function() {
	    	if(this._atop == null) {
	    		this.getAXY();
	    	}
	    	return this._atop;
	    },
	    /**
	     * 获取绝对left值.
	     * @return 返回left
	     */
	    getALeft:function() {
	    	if(this._aleft == null) {
	    		this.getAXY();
	    	}
	    	return this._aleft;
	    },
	    /**
	     * 执行焦点事件.
	     * @param ev 事件
	     */
	    doFocus:function(ev) {
	    	this.logInfo("focus");
	    	if(typeof this.onFocus == "function") {
	    		this.onFocus(ev);
	    	}
	    },
	    /**
	     * 执行失去焦点事件.
	     * @param ev 事件
	     */
	    doBlur:function(ev){
	    	this.logInfo("blur");
	    	if(typeof this.onBlur == "function") {
	    		this.onBlur(ev);
	    	}
	    },
	    /**
	     * 鼠标按下事件.
	     * @param ev 事件
	     */
	    doMouseDown:function(ev) {
	    	if(typeof this.onMouseDown == "function") {
	    		this.onMouseDown(ev);
	    	}
	    },
	    /**
	     * 鼠标移动事件.
	     * @param ev 事件
	     */
	    doMouseMove:function(ev) {
	    	if(typeof this.onMouseMove == "function") {
	    		this.onMouseMove(ev);
	    	}
	    },
	    /**
	     * 鼠标弹起事件.
	     * @param ev 事件
	     */
        doMouseUp:function(ev) {
	    	if(typeof this.onMouseUp == "function") {
	    		this.onMouseUp(ev);
	    	}
	    },
	    /**
	     * 按键按下事件.
	     * @param ev 事件
	     */
	    doKeyDown:function(ev, key) {
	    	if(typeof this.onKeyDown == "function") {
	    		this.onKeyDown(ev, key);
	    	}
	    	return true;
	    },
	    /**
	     * 按键弹起事件.
	     * @param ev 事件
	     */
	    doKeyUp:function(ev, key) {
	    	if(typeof this.onKeyUp == "function") {
	    		this.onKeyUp(ev, key);
	    	}
	    	return true;
	    },
	    /**
	     * 鼠标滚动事件.
	     * @param ev 事件
	     */
	    doMouseWheel:function(ev) {
	    	if(typeof this.onMouseWheel == "function") {
	    		this.onMouseWheel(ev);
	    	}
	    },
	    doResize:function(ev) {
	    	if(typeof this.onResize == "function") {
	    		this.onResize(ev);
	    	}
	    },
	    doShow:function() {
	    	if(typeof this.onShow == "function") {
	    		this.onShow();
	    	}
	    },
	    doHide:function() {
	    	if(typeof this.onHide == "function") {
	    		this.onHide();
	    	}
	    },
	    /**
	     * 设置容器.
         * @name setContainer
         * @param {object} container 容器对象
         * @ignore
	     */
	    setContainer:function(container) {
	    	
	    },
	    /**
	     * 获取容器.
	     * @return 返回
	     */
	    getContainer:function() {
	    	return this.control[0];
	    },
	    /**
	     * 添加子控件.
	     * @param element 子控件
	     */
	    appendChild:function(element){
	    	this.thisWindow.appendChild(element);
	    },
	    /**
	     * 删除子控件.
	     * @param element 子控件
	     */
	    removeChild:function(element) {
	    	for(var i = 0, len = this.childComponent.length; i < len; i++) {
	    		if(this.childComponent[i].index == element.index) {
	    			this.childComponent.splice(i, 1);
	    			this.getContainer().removeChild(element.getContainer());
	    			break;
	    		}
	    	}
	    },
	    /**
	     * 设置父控件.
	     * @param element 父控件
	     * @param notAppend 不添加到元素.
	     */
	    setParent:function(element, notAppend){
	    	if(element.isComponent) {
	    		//如果是控件则调用通用添加
	    		if(notAppend != true) {
	    		    element.getContainer().appendChild(this.thisWindow);
	    		}
	    		this.parent = element;
	    		this.parent.childComponent.push(this);
	    	} else {
	    		//如果是dom，则用此分支添加
		    	if(element.appendChild != null) {
		    		if(notAppend != true) {
		    	        element.appendChild(this.thisWindow);
		    	    }		    	    
		    	    this.parent = $(element);
		    	} else {
		    		if(notAppend != true) {
		    		    element.append(this.thisWindow);
		    		}		    		    
		    		this.parent = element;
		    	}
		    	if(notAppend != true) {
		    		this._asynRun(function(){
		    			if(typeof this.getAXY === "function" && this.thisWindow.offsetWidth > 0) {
		    			    this.getAXY();
		    			}
		    		}, 200);		    	    
		    	}
		    	if(this.parent[0].childComponent == null) {
		    		this.parent[0].childComponent = [];
		    	}
		    	this.parent[0].childComponent.push(this);
	    	}
	    	
	    },
	    /**
	     * 获得宽或高.
	     */
	    getWidthOrHeight : function(elem,name,area){
			//处理elem为null的情况
			if(!elem || elem.length===0){return 0;}
			if(elem.length >= 1){elem = elem[0];}
			var res,_res;				
			if(name === "width"){
				res = elem.style.width;
			}else{
				res = elem.style.height;
			}
			//过滤
			if((area !== "outer" && area !== false) && res && res !== 0){return parseFloat(res) || 0;}
			var defView = document.defaultView, isDv = true, computedStyle;
			if(!defView){isDv = false;}
			if(isDv){
				computedStyle = defView.getComputedStyle(elem,null);
			}else{
				computedStyle = elem.currentStyle;
			}
			if(computedStyle){
				var resStys,ores,_ores,len=6;
				if(name === "width"){
					if(isDv){
						resStys = this.ELEM_WIDTH_STYLE;
					}else{
						resStys = this.IE_ELEM_WIDTH_STYLE;
					}
					ores = elem.offsetWidth;
				}else{
					if(isDv){
						resStys = this.ELEM_HEIGHT_STYLE;
					}else{
						resStys = this.IE_ELEM_HEIGHT_STYLE;
					}
					ores = elem.offsetHeight;
				} 
				if(ores > 0){
					ores = parseFloat( ores ) || 0;
					for(var i=0; i<len; i++){
						if(isDv){
							_ores = computedStyle.getPropertyValue( resStys[i] );
						}else{
							_ores = computedStyle[resStys[i]];
						}
						if(!_ores || _ores==="0px" || _ores.indexOf("px") <= 0){continue;}
						_ores = parseFloat( _ores ) || 0;
						if(i <= 3){
							ores -= _ores;
						}else{
							ores += _ores;
						}
					}
					res = ores;
				}else{
					res = parseFloat( res ) || 0;
					for(var i=0; i<len; i++){
						if(isDv){
							_res = computedStyle.getPropertyValue( resStys[i] );
						}else{
							_res = computedStyle[resStys[i]];
						}
						if(!_res || _res==="0px" || _res.indexOf("px") <= 0){continue;}
						_res = parseFloat( _res ) || 0;
						res += _res;
					}
				}
				return res;
			}
			return 0;
		},
	    /**
	     * 获取当前dom容器.
	     * @return 返回窗口元素
	     */
	    getWindow:function(){
	    	return this.thisWindow;
	    },
	    /**
	     * 获取文字的像素宽.
	     * @return 返回宽度
	     */
	    getTextWidth:function(str, size, weight, family) {   
	    	if(str == null) return 0;
	    	if(typeof str != "string") {
	    		str = str + "";
	    	}
	    	if(str.indexOf("<") != -1) {
	    	    str = str.replace(/<(a|span|div|li|ul|table|tr|td|input|i) [^<>]+>([^<>]+)?<\/\1>/gi,"$2")
	    	}
	    	this._textSpan.style.display = "";
            if(size != null) {
            	this._textSpan.style.fontSize = size;
            }
            //字体样式
            if(weight != null) {
            	this._textSpan.style.fontWeight = weight;
            }
            if(family != null) {
            	this._textSpan.style.fontFamily = family;   
            }           
            this._setHtml(this._textSpan, str);
            var rs = this._textSpan.offsetWidth;
            this._textSpan.style.display = "none";
            return rs;
	    },
	    
	    getStyle:function(elem, name) {
	    	if(elem.style[name]) {
	    		return elem.style[name];
	    	} else if(elem.currentStyle) {
	    		return elem.currentStyle[name];
	    	} else if(document.defaultView && document.defaultView.getComputedStyle) {
	    		name = name.replace(/[A-Z]/g, "-$1").toLowerCase();
	    		var s = document.defaultView.getComputedStyle(elem, "");
	    		return s && s.getPropertyValue(name);
	    	} else {
	    		return "";
	    	}
	    },
	    /**
	     * 获取指定宽度可容纳的字符长度.
	     */
	    getTextLen:function(fontSize, width) {
	    	var pw = fontSize * this._sizew;
	    	return parseInt(width/pw, 10);
	    },
	    /**
	     * 获取显示的字符串.
	     */
	    getShowStr:function(str, fontSize, width, height) {
	    	
	    	//宋体	    	
	    	var key = str + "@" + width + "@" + fontSize;// + "@" + weight + "@" + family;
            if(this._textHeightJson == null) {
            	this._textHeightJson = {};
            }
            var rs = this._textHeightJson[key];
            if(rs == null) {
            	if(fontSize == null || fontSize === "") {
    	    		fontSize = 12;
    	    	}    	    	
            	fontSize = parseInt(fontSize, 10); 
            	if(fontSize < 12 && this.getBrowser("chrome") === true) {
    	    		fontSize = 12;
    	    	}
                width = parseInt(width, 10);
                var pw = fontSize * this._sizew * 1.7;
                var ph = fontSize * this._sizeh * 1.11;
                var rs = "";
                var sumWidth = 0;
                var sumHeight = ph;
                var rowcount = 0;
                var kc = 0;
                var cw = 0, pcw = 0, pkc = 0;
                var sary = [];
                if(pw < width) {
	                for(var i = 0, len = str.length; i < len; i++) {
	                    var cs = str.charCodeAt(i);
	                    cw = 0;
	                    if(cs > 256) {
	                	    cw =   2 * pw;
	     	            } else {
	     	            	cw = pw;
	     	            }
	                	if(sumWidth + cw < width) {
	                	    kc++;
	                	    sumWidth += cw;
	                	} else if(sumHeight + ph < height) {
	                		sumHeight = sumHeight + ph;
	                		rowcount++;
	                		sumWidth = cw;
                            pkc = kc;
                            kc++;
	                	} else {
	                		break;
	                	}
	                }
                    if(kc < len - 1) {
	                   rs = str.substring(0, kc - 1) + "…";
                    } else {
                           rs = str;
                    }
	                this._textHeightJson[key] = rs;
                } else {
                	return "…";
                }	            
            }//if
	        return rs;
	    },
	    /**
	     * 自动适应列宽
	     */
	    autoSuitWidth:function(fieldName) {
	    	
	    },
	    /**
	     * 获取高度.
	     * @return 返回高度
	     */
	    getHeight:function(el) {
	    	 var height = this.getOption().height;
	    	 if(el != null) {
	    		 height = el.offsetHeight;
	    	 }
	    	 //if(/\d+%$/.test(height)) {
	    	 //	 return this.thisWindow.offsetHeight;
	    	 //} else {
	    	 return height;
	    	 //}
	    },	
	    /**
	     * 设置高度.
	     * @param height 高度
	     * @param doRs 执行变更函数
	     */
	    setHeight:function(height, doRs) {
	    	if(this.getOption().height != height) {
		    	this.getOption().height = height;
	    	}
	    	doRs = this.getBooleanValue(doRs, true);
		    if(doRs && this._hasResize()) {
		        this._doResize();
		    }
	    },
	    /**
	     * 获取宽度
	     * @return 返回宽度
	     */
	    getWidth:function(el) {
	    	 var width = this.getOption().width
	    	 if(el != null) {
	    		width = el.offsetWidth;
	    	 }
	    	 //if(/\d+%$/.test(width)) {
	    	 //	 return this.thisWindow.offsetWidth;
	    	 //} else {
	    	 return width;
	    	 //}
	    },	  
	    /**
	     * 设置宽度.
	     * @param width 宽度
	     * @param doRs 执行变更函数
	     */
	    setWidth:function(width, doRs){
	    	if(this.getOption().width != width) {
		    	this.getOption().width = width;
	    	}
		    doRs = this.getBooleanValue(doRs, true);
			if(doRs && this._hasResize()) {
			     this._doResize();
			}	    	
	    },
	    /**
	     * 设置顶点.
	     * @param top 顶点
	     * @param doRs 执行变更函数
	     */
	    setTop:function(top, doRs) {
	    	if(this.getOption().top != top) {
		    	this.getOption().top = top;
	    	}
	    	this.logInfo("Window.setTop");
		    doRs = this.getBooleanValue(doRs, true);
		    if(doRs && this._hasResize()) {
		        this._doResize();
		    }
	    },
	    /**
	     * 获取当前顶点位置
	     * @return 顶点坐标
	     */
	    getTop:function() {
	    	return this.getOption().top;
	    },
	    /**
	     * 设置左边位置.
	     * @param left 左边位置
	     * @param doRs 执行变更函数
	     */
	    setLeft:function(left, doRs) {
	    	if(this.getOption().left != left) {
		    	this.getOption().left = left;
	    	}
	    	this.logInfo("Window.setLeft");
		    doRs = this.getBooleanValue(doRs, true);
		    if(doRs && this._hasResize()) {
		        this._doResize();
		    }
	    },
	    /**
	     * 获取左边位置值.
	     * @return 返回
	     */
	    getLeft:function() {
	    	return this.getOption().left;
	    },
	    /**
	     * 设置控件对齐
	     * @param align 对齐方式
	     */
	    setComAlign:function(align) {
	    	if(align == "center") {
	    		this.thisWindow.style.margin = "0 auto";
	    	} else {
	    		this.thisWindow.style.cssFloat = align;
	    		this.thisWindow.style.styleFloat = align;
	    	}
	    },
	    /**
	     * 开始刷新
	     */
	    beginUpdate:function() {
	    	this._update = false;
	    },
	    /**
	     * 结束刷新
	     */
	    endUpdate:function() {
	    	this._update = true;
	    },
	    /**
	     * 获取鼠标按键类型
	     * @param 事件对象
	     * @return 返回
	     */
	    getMouseButton:function(ent) {
	    	if(ent.button == 2 || ent.button == 3) {
	    		return this.mouseType.mtRight;
	    	} else {
	    		return this.mouseType.mtLeft;
	    	}
	    },
	    /**
	     * 获取inputer对象.
	     */
	    getInputer:function() {
	    	return this.inputer;
	    },
	    /**
	     * 返回控件dom对象.
	     * @name getControl
	     * @return 返回dom对象
	     */
	    getControl:function() {
	    	return this.control;
	    },
		/**
		 * 刷新UI(为了兼容ECPGrid表格添加的方法).
		 * @ignore
		 */
		isUpdateUI:function() {
			return true;
		},
		/**
		 * 是否可用.
		 */
		isenable:function() {
			return this.getOption().disabled !== true;
		},
		/**
		 * 不可用属性设置.
		 * @name disable
		 */
		disable:function() {
			this._enabled = false;
			this.getOption().disabled = true;
			if(typeof this.refresh == "function") {
				this.refresh();
			}
		}, 
		/**
		 * 隐藏控件.
		 * @name hide
		 */
		hide:function() {
			this.thisWindow.style.display = "none";
		},
		/**
		 * 显示控件.
		 * @name hide
		 */
		show:function() {
			this.thisWindow.style.display = "";
		},
		/**
		 * isShow是否处于显示状态.
		 */
		isShow:function() {
			return this.thisWindow != null && this.thisWindow.offsetWidth > 0;
		},
		/**
		 * 可用属性设置.
		 * @name enable
		 */
		enable:function() {
			this._enabled = true;
			this.getOption().disabled = false;
			if(typeof this.refresh == "function") {
				this.refresh();
			}
		},
		/**
		 * 是否焦点.
		 */
		isFocus:function() {
			return this.focus;
		},
	    /**
	     * 设置焦点事件.
	     */
	    setFocus:function() {	    	
	    	this.focus = true;
	    	this.hasSelect = true;
	    	if(this.doFocus() === false) {
	    		this.focus = false;
	    	} else {    	
	    	    this.focus = true;
	    	}
	    },
	    /**
	     * 设置失去焦点事件.
	     */
	    setBlur:function() {	    	
	    	this.focus = false;
	    	this.hasSelect = false;
	    	if(this.doBlur() === false) {	    	
	    	    this.focus = true;
	    	} else {
	    		this.focus = false;
	    	}
	    },
	    _style:function(dom, key, value) {
	    	if(dom == null) return;
	    	if(dom.style[key] != value) {
	    		dom.style[key] = value;
	    	}	    	
	    },
	    _setHtml:function(dom, value, isText) {
	    	if(value == null) value = "";
	    	var tp = typeof value;
	    	if(tp === "string") {
	    		if(isText !== false) {
	    			value = value.replace(/</g, "&lt;").replace(/>/g,"&gt;");
	    		}
	    		dom.innerHTML = value;
	    	} else if(tp == "object") {
	    		if(value.tagName != null && value.tagName != "script") {
	    			dom.innerHTML = "";
	    			dom.appendChild(value);
	    		}
	    	} else {
	    		dom.innerHTML = value;
	    	}
	    },
	    /**
	     * 控制选择事件函数.
	     */
	    _onselectstart:function(e) {
	    	var ent = e || window.event;
            var tg = ent.target || ent.srcElement;
            var cancel = false;
            if(!this.shiftKeyDown) {
	            var cancel = tg.tagName == 'INPUT' || tg.tagName == "TEXTAREA";	
//	            if(tg.value === "" || tg.value == null) {
//	            	cancel = false;
//	            } 
            }	
            ent.returnValue = cancel;
            return cancel;
	    },
		/**
		 * 卸载控件.
		 * @name enable
		 */
		destory:function() {
			if(window._qzz_component_list) {
				delete window._qzz_component_list[this.index];
			}
			this.clearEvent();
			this.base();
		}
	});	
	if(window._bindRenderFunc == null) {
		window._bindRenderFunc = function(key, ccls) {
			if($ != null) {
				$.fn[key] = function(opt) {					
				    var _qzzUI = null;
					if(this.length > 0) {
					    _qzzUI = this[0]._component;
					    if(opt !== true && opt !== "true"){
						    _qzzUI = new ccls(this, opt);
						    this[0]._component = _qzzUI;
					    }
					}
					return _qzzUI;
				};
			};
		};
	}
	
	return qzz.ui.window;
});